feat: Split analysis-only and runtime-only CheckErrors #6626
+2,832
−2,016
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Some input would be appreciated!
StaticCheckErrorKind: 98 total variantsCheckErrorKind: 87 total variantsCommonCheckErrorKind): 26StaticCheckErrorKind: 34CheckErrorKind: 22Why Separating the two?
Separating static from "execution-time" Check errors would make the code explicit about what the contract analysis guarantees vs what can only be checked at runtime. Currently, all errors seem possible at any time.
More importantly, this split enables a second phase of cleanup: many
CheckErrorKindat runtime are actually safeguards for unreachable code that's already protected by contract analysis. Even the relative tests bypass the contract_analysis to stimulate the unreachable code paths. Once separated, we can identify these and replace them withCheckError::Expects(or a new variant that accepts the transaction but marks it as failed for consensus safety).We currently have 79
CheckErrorKind variants(58 shared with static). After this cleanup, we'd likely reduce this to ~40 actual runtime errors, making the codebase significantly clearer about what can actually fail at runtime.WIP: currently the
CommonCheckErrorKindenum is public, but should become private and invisible to users of theclarity-typesandclaritycrates (can't be truly private because theclaritycrate also needs it. However, this is solvable by making it public but ensuring all public functions only returnStaticCheckErrororCheckError)While trying to achieve this clean public API, I've tried multiple approaches, but each has significant problems (uuugly):
Duplicate public functions
Problems:
clartyhas to return aCommonCheckErrorand use a function inclarity-types)Generic error type
Problems:
ListTypeData :::new_list::<CheckError>(...).unwrap()Open questions:
Looking for feedback on whether to push through with a better approach, or abandon this split entirely.
Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yamlandrpc-endpoints.mdfor v2 endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo